package com.bmft.task01.controller;

import com.bmft.task01.service.impl.AnimalServiceImpl;
import com.bmft.task01.util.enum_.MainMenuEnum;

import java.util.Scanner;

/**
 * This is menu class.
 * Helper class is to simplify the Driver.
 *
 * @author Jarvan
 * @version 1.0
 * @create 2020/9/26 10:12
 */
public class Helper {

    private static AnimalServiceImpl animalService = new AnimalServiceImpl();


    /**
     * This is menu start.
     */
    public static void start() {


        System.out.println("===Welcome to Animal manage System===");
        System.out.println(MainMenuEnum.INSERT.getCode() + ". " + MainMenuEnum.INSERT.getMeans());
        System.out.println(MainMenuEnum.DELETE.getCode() + ". " + MainMenuEnum.DELETE.getMeans());
        System.out.println(MainMenuEnum.UPDATE.getCode() + ". " + MainMenuEnum.UPDATE.getMeans());
        System.out.println(MainMenuEnum.QUERY.getCode() + ". " + MainMenuEnum.QUERY.getMeans());
        System.out.println();
        System.out.print("input your option: ");
        Scanner scanner = new Scanner(System.in);
        int inputOption = scanner.nextInt();
        if (inputOption == MainMenuEnum.INSERT.getCode()){
            animalService.insert();
            start();
        }else if (inputOption == MainMenuEnum.DELETE.getCode()){
            animalService.delete();
            start();
        }else if (inputOption == MainMenuEnum.UPDATE.getCode()){
            animalService.update();
            start();
        }else if (inputOption == MainMenuEnum.QUERY.getCode()){
            animalService.displayAnimals();
            start();
        }else {
            System.err.println("your input has some error ,please try it again.");
            start();
        }

    }
}
